package com.zhixinglu.spring.boot.mqtt.tio.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

/**
 * <p>
 * MQTT工具类
 * </p>
 * MQTT消息处理工具类
 *
 * @author weixin
 * @date 2022/12/21 15:41
 */
public class MqttUtil {

    /**
     * 生成消息ID
     * @return String
     */
    public static String generateClientId(){
        return generateClientId(1, 2);
    }

    public static String generateClientId(long workerId, long dataCenterId){
        Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId);
        return snowflake.nextIdStr();
    }

    /**
     * 生成客户端ID
     * @param prefix {@link String} 前缀
     * @return {}@link String}
     */
    public static String generateClientId(String prefix){
        return generateClientId(prefix, 1, 2);
    }

    public static String generateClientId(String prefix, long workerId, long dataCenterId){
        Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId);
        return prefix + "_" + snowflake.nextIdStr();
    }



}
